package com.anlu.pattern.action.command;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * Description:命令调用类
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/10/13 9:48
 */
public class Broker {
    private List<Order> orderList = new ArrayList<Order>();

    public void takeOrder(Order order){
        orderList.add(order);
    }

    public void placeOrders(){
        for (Order order : orderList) {
            order.execute();
        }
//        orderList.clear();
    }

    public void  undo(){
        Order lastOrder = orderList.get(orderList.size() - 1);
        lastOrder.undo();
        orderList.remove(orderList.size() - 1);
    }
}
